package edu.uic.ids517.model;

public class BmiBean {

	//inputs
	private String units;
	private double weight;
	private double height;

	//outputs
	private double bmi;
	private double bmiPrime;
	private String bmiCategory;
	private String errorMessage;

	//control
	private boolean status;

	//constants
	private static final double siConstant = 1.0;
	private static final double imperialConstant = 703.0;
	private static final double bmiUpperLimit = 25.0;

	public static double categoryLimit [] = {0, 15.0, 16.0, 18.5, 25.0, 30.0, 35.0, 40.0};
	private String categoryDescription [] = {"Error", "Very Severely Underweight", "Severely Underweight", "Underweight", "Normal Healthy Weight", "Obese", "Obese II", "Very Obese"};

	public BmiBean(String units, double weight, double height) {
		super();
		this.units = units;
		this.weight = weight;
		this.height = height;
	}



	public String getUnits() {
		return units;
	}



	public void setUnits(String units) {
		this.units = units;
	}



	public double getWeight() {
		return weight;
	}



	public void setWeight(double weight) {
		this.weight = weight;
	}



	public double getHeight() {
		return height;
	}



	public void setHeight(double height) {
		this.height = height;
	}



	public double getBmi() {
		return bmi;
	}



	public double getBmiPrime() {
		return bmiPrime;
	}



	public String getBmiCategory() {
		return bmiCategory;
	}



	public BmiBean() {
		// TODO Auto-generated constructor stub
	}

	public void computeBmi(){
		errorMessage = "";
		status = true;
		
		if((weight <= 0.0) || (height <= 0.0)){
			errorMessage = "Bad input weight " + weight + " , height = " + height;
			status = false;			
		} // end if
		
		double constant = siConstant;
		if(!units.equalsIgnoreCase("SI"))
			constant = imperialConstant;
		
		bmi = (constant * weight)/(height * height);
		bmiPrime = bmi/bmiUpperLimit;
		
		bmiCategory = categoryDescription[categoryDescription.length - 1];
				
		for(int i=0; i< categoryLimit.length; i++){
			if(bmiPrime <= categoryLimit[i]){
				bmiCategory = categoryDescription[i];
				break;
			} //end if
		} //end for
				
	}

}
